﻿<?php
require_once ('start_session.php');
require_once('db.php');

	// hämtar bilder från databasen
	function getImages(){
		$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
		if(isset($_SESSION['id'])){
			$user_id = $_SESSION['id'];		
		}
		else{
			$user_id = 0;		
		}
		// hämtar namn och id på bilderna		
		$query = "SELECT name,id
				  FROM image
				  WHERE user_id = $user_id 
				  OR user_id = 0
				  ORDER BY id DESC";
		$result = mysqli_query($dbc, $query);
		echo "<div>";
			while($card = mysqli_fetch_assoc($result)){	
				// visning av bilderna
				echo "<span id='{$card['id']}'>" .
				"<img src='{$card['name']}' id='{$card['id']}' class='draggable ui-widget-content' >" .
				"<img class='cross' src='images/cross-icon.png' alt='small'/>" .
				"</span>";
			}	
		echo "</div>";	
	}
?>
